# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=libpsl
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.21.0
pkgrel=2
pkgdesc="Public Suffix List library (mingw-w64)"
arch=('any')
url="https://github.com/rockdaboot/libpsl"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-libidn2"
         "${MINGW_PACKAGE_PREFIX}-libunistring"
         "${MINGW_PACKAGE_PREFIX}-gettext")
makedepends=("${MINGW_PACKAGE_PREFIX}-libxslt"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-gettext"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc")
source=("https://github.com/rockdaboot/libpsl/releases/download/${_realname}-${pkgver}/${_realname}-${pkgver}.tar.gz"
        "fix-gtk-doc.patch")
sha256sums=('41bd1c75a375b85c337b59783f5deb93dbb443fb0a52d257f403df7bd653ee12'
            'f32ed3054b4ecd8a70d95ec6d581980a8b3f9f9e76e282483e6803cc12fd1adc')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}

  # https://gitlab.gnome.org/GNOME/gtk-doc/issues/103
  patch -p1 -i "${srcdir}"/fix-gtk-doc.patch

  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  LIBS+="-lws2_32" \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared \
    --enable-gtk-doc \
    --enable-runtime=libidn2

  LC_CTYPE=en_US.UTF-8 make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  make check || true
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
